package tw.com.softleader.reins.demo.movie.service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import tw.com.softleader.reins.demo.movie.entity.Movie;

//Complete
public class MovieService { 
	
	private static List<Movie> movieDataBase = new ArrayList<Movie>();
	
	static{
		//暫時替代資料庫的假資料
		Movie movie = new Movie();
		movie.setId(1L);
		movie.setName("Movie1");
		movie.setDirector("Director1");
		movie.setType("Type1");
		movie.setLength(new Timestamp(new Date().getTime()));
		movieDataBase.add(movie);
		
		movie = new Movie();
		movie.setId(2L);
		movie.setName("Movie2");
		movie.setDirector("Director2");
		movie.setType("Type2");
		movie.setLength(new Timestamp(new Date().getTime()));
		movieDataBase.add(movie);
		
		movie = new Movie();
		movie.setId(3L);
		movie.setName("Movie3");
		movie.setDirector("Director3");
		movie.setType("Type3");
		movie.setLength(new Timestamp(new Date().getTime()));
		movieDataBase.add(movie);
		
		movie = new Movie();
		movie.setId(4L);
		movie.setName("Movie4");
		movie.setDirector("Director4");
		movie.setType("Type4");
		movie.setLength(new Timestamp(new Date().getTime()));
		movieDataBase.add(movie);
	}

	public List<Movie> getAll() {
		List<Movie> movies = new ArrayList<Movie>();
		for (Movie movie : movieDataBase) {
			movies.add(movie);
		}
		
		return movies;


	}

	public Movie getById(Long id) {

		for (Movie movie : movieDataBase) {
			if (movie.getId().equals(id)) {
				return movie;
			}
		}
		return null;
	}
}
